package sdufe.lele.dao;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import sdufe.lele.model.AccountType;

import java.util.ArrayList;

@Repository
@Mapper
public interface AccountTypeMapper {

    @Delete("delete from accounttype where accountTypeId = #{accounttypeid}")
    int deleteByPrimaryKey(@Param("accounttypeid") Integer accounttypeid);

    @Delete("delete from accounttype where accountTypeName = #{name}")
    int deleteByName(@Param("name")String name);

    @Insert("insert into accounttype (accountTypeName,accountTypeLevel,accountTypeUserPhone) values (#{accounttypename},#{accounttypelevel},#{accounttypeuserphone})")
    int insertSelective(AccountType record);

    @Select("select * from accounttype where accountTypeId = #{accounttypeid}")
    AccountType selectByPrimaryKey(@Param("accounttypeid") Integer accounttypeid);

    @Update("update accounttype set accountTypeName = #{new}  where accountTypeName =#{old}")
    int updateName(@Param("old") String oldName ,@Param("new") String newName);


    /**
     *
     *
     * @return 收入/支出的typelist
     */
    @Select("select * from accounttype  ")
    @Results({
            @Result(id = true, column = "accountTypeId", property = "accounttypeid"),
            @Result(column = "accountTypeName", property = "accounttypename"),
            @Result(column = "accountTypeLevel", property = "accounttypelevel")
    })
    ArrayList<AccountType> selectAll ();

    @Select("select * from accounttype where accountTypeUserPhone = #{phone} ")
    @Results({
            @Result(id = true, column = "accountTypeId", property = "accounttypeid"),
            @Result(column = "accountTypeName", property = "accounttypename"),
            @Result(column = "accountTypeLevel", property = "accounttypelevel")
    })
    ArrayList<AccountType> selectAllByPhone (@Param("phone") String phone);

    @Select("select * from accounttype where accountTypeLevel = #{inout}  " )
    @Results({
            @Result(id = true, column = "accountTypeId", property = "accounttypeid"),
            @Result(column = "accountTypeName", property = "accounttypename"),
            @Result(column = "accountTypeLevel", property = "accounttypelevel")
    })
    ArrayList<AccountType> selectInOut(@Param("inout") Integer inout);

    @Select("select * from accounttype where accountTypeLevel = #{inout} and accountTypeUserPhone = #{phone}  " )
    @Results({
            @Result(id = true, column = "accountTypeId", property = "accounttypeid"),
            @Result(column = "accountTypeName", property = "accounttypename"),
            @Result(column = "accountTypeLevel", property = "accounttypelevel")
    })
    ArrayList<AccountType> selectInOutByPhone(@Param("inout") Integer inout,@Param("phone") String phone);

}